home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / LANG / SCHEME / VSCM / doc / DESCRIPTIO next >
Text File  |  1994-08-05  |  18KB  |  673 lines

  1. Improvements in V0r2 (over V0r1):
  2.  
  3.     - numerous bugs in numeric code fixed
  4.     - numerous other bugs fixed
  5.     - subdirectory ``slib'' included (for SLIB support)
  6.  
  7. Improvements in V0r1 (over V0r0):
  8.  
  9.     - bugs fixed
  10.     - new streamlined memory allocator / GC
  11.     - more support for files and file ports
  12.     - VM somewhat faster
  13.     - memory dump format much more compact
  14.     - portability problem in memory dump format eliminated (was
  15.       related to 64 bit machines like the DEC Alpha)
  16.     - error messages (somewhat) improved
  17.  
  18. Improvements (since vscmIISep29) relevant to public use:
  19.  
  20.     - several bugs fixed
  21.     - support for coroutines added
  22.     - ``ticking'' (to allow for preemptive scheduling)
  23.     - multi-argument continuations
  24.     - interface to some extensions changed
  25.     - I/O interface generalized
  26.     - generic ports added
  27.     - ``string I/O'' added
  28.     - get and put!
  29.  
  30.  
  31. Command line argument handling:
  32. ===============================
  33.  
  34. The following command line switches are recognized by VSCM:
  35.  
  36.     -b bootfile
  37.  
  38.         overrides DEFAULT_BOOTFILE and $VSCMBOOT  (a definition of
  39.         the environment variable VSCMBOOT would take precedence
  40.         over DEFAULT_BOOTFILE)
  41.  
  42.     -b -
  43.  
  44.         does not load any bootfile
  45.  
  46.     -a asmfile
  47.  
  48.         reads VSCM assembly code definitions in asmfile after
  49.         loading the bootfile
  50.  
  51.     -a -
  52.  
  53.         reads assembly code in standard input after loading
  54.         the bootfile
  55.  
  56.     -d dumpfile
  57.  
  58.         writes system image into dumpfile immediately after
  59.         reading the bootfile (if any) and processing the asmfile
  60.         (if any).
  61.  
  62.     -p dump_prefix
  63.  
  64.         overrides DEFAULT_DUMP_PREFIX
  65.         this is used for the ``executable'' memory image
  66.         hack (see below)
  67.  
  68. The processing of these standard options is done left-to-right until
  69. one of the following events (whichever comes first) occurs:
  70.  
  71.     - there is no further command line argument
  72.     - the next argument does not start with ``-''
  73.     - the next argument is ``-'' by itself
  74.     - the next argument is ``--'' (``--'' will be skipped in this case)
  75.  
  76. All command line arguments not processed or skipped are passed to the
  77. Scheme program.  In what follows we will refer to those remaining
  78. arguments as ``the arguments''.  Here are the details:
  79.  
  80.     1. on system startup (default boot image):
  81.  
  82.        - the arguments are stored as a list into the global variable
  83.         command-line-arguments
  84.        - the arguments are interpreted as filenames and LOADed in
  85.          left-to-right order
  86.  
  87.     2. After returning from ``(dump "filename")''.
  88.  
  89.        - In the program (process) which originally executed
  90.          ``(dump "filename")'' #f will be returned.
  91.        - In a process that was created by running VSCM with
  92.         ``-b filename''
  93.          the call to ``dump'' returns a list of the arguments.
  94.          Note, that ``executing'' a memory image (the file written by
  95.          ``dump'') is equivalent to running VSCM with the appropriate
  96.          ``-b'' switch set.
  97.  
  98.  
  99. Executable memory images:
  100. =========================
  101.  
  102. I incorporated a cute hack suggested by Henry Cejtin (NEC) which
  103. allows to ``run'' memory images directly.  All which needed to be done
  104. was:
  105.  
  106.     - write a line of the form
  107.         #!/a/path/to/the/vscm/executable/here -b
  108.       into the first line of every memory image
  109.  
  110.     - ignore the first line of every memory image
  111.  
  112. This works on all Unix systems which have the ``#!'' kernel hack.  On
  113. other systems it will not work (but it will not hurt either).  VSCM
  114. does not set permission bits to make the memory image executable --
  115. this has to be done manually.  (ANSI C does not provide a portable way
  116. to set permission bits.)
  117.  
  118.  
  119. Open compilation:
  120. =================
  121.  
  122. Calls to the procedures NOT, CONS and any member of the (infinite!)
  123. CAR/CDR family are ``open compiled'' (aka ``in-lined'').  This allows
  124. for better performance, but strictly speaking it also violates the
  125. Scheme semantics: A subsequent redefinition of either of these
  126. functions has no effect any more.  Therefore, VSCM (like many other
  127. Scheme implementations) offers to disable in-lining of these function
  128. calls by running
  129.  
  130.     (open-compilation #f)
  131.  
  132. Open compilation can be enabled again using
  133.  
  134.     (open-compilation #t)
  135.  
  136. The function ``open-compilation'' always returns the old status.
  137.  
  138. While open compilation is enabled VSCM will refuse to accept any code
  139. which (possibly) redefines or assigns to an open-compiled primitive.
  140.  
  141.  
  142. Coroutines:
  143. ===========
  144.  
  145. The routines used to work with coroutines in VSCM are described below.
  146. They can easily be implemented in any R4RS Scheme implementation using
  147. ``call-with-current-continuation''.  Their implementation as
  148. primitives was done because of efficiency considerations.
  149.  
  150. The coroutine interface was added to VSCM on demand by Greg Wilson.
  151.  
  152.  
  153. Continuations with multiple arguments:
  154. ======================================
  155.  
  156. VSCM now provides full support for ``call-with-values'' and ``values''.
  157. Moreover, the new facility was immediately used for other extensions
  158. like ``divide'' and ``string-read'' (see description below).
  159.  
  160. Generic ports:
  161. ==============
  162.  
  163. VSCM now has a feature called ``generic ports''.  Ports are treated as
  164. an abstract data type supporting a number of operations. (Those are:
  165. for input ports: read, read-char, peek-char, char-ready?, and close;
  166. for output ports: write, display, write-char, newline, flush, close.)
  167.  
  168. VSCM makes no attempt to automatically enforce that ``write'' is
  169. equivalent to so-many ``write-char''s.  The behaviour is completely
  170. in the hands of the programmer.
  171.  
  172. A straightforward implementation of ``string ports'' is given in the
  173. appendix.
  174.  
  175.  
  176. Reading from and writing to strings:
  177. ====================================
  178.  
  179. See description below.
  180. This feature was added to allow the implementation of string ports (see
  181. appendix).
  182.  
  183.  
  184. Rudimentary file system interface:
  185. ==================================
  186.  
  187. VSCM now comes with procedures to remove and rename files.
  188.  
  189.  
  190. File ports are more flexible:
  191. =============================
  192.  
  193. The interface to the ``open-*-file'' procedures has been extended in a way
  194. which resembles fopen's ``mode'' argument.  It is possible to select
  195. binary mode (as opposed to the default text mode), and you can ask for
  196. permission to ``update'' a file (open for reading and writing at the same
  197. time).  Also, it is possible to specify which kind of buffering
  198. (full, line, or none) is desired.
  199.  
  200. A ``seek-and-tell'' procedure was added. which essentially is a
  201. combination of ``fseek'' and ``ftell''.
  202.  
  203. In addition to that you can open a ``temporary'' file (which is unnamed
  204. and which automatically goes away after VSCM quits).
  205.  
  206.  
  207. The timer:
  208. ==========
  209.  
  210. The timer was added to facilitate preemptive scheduling.
  211.  
  212.  
  213. Get and put!:
  214. =============
  215.  
  216. Property lists are now implemented.
  217.  
  218.  
  219. Character names:
  220. ================
  221.  
  222. VSCM provides a somewhat richer syntax to specify character constants.
  223.  
  224.     1. More symbolic character names:
  225.  
  226.         #\Alarm        ~=~ '\a'
  227.         #\Backspace    ~=~ '\b'
  228.         #\Tab        ~=~ '\t'
  229.         #\Newline    ~=~ '\n'
  230.         #\VTab        ~=~ '\v'
  231.         #\Return    ~=~ '\r'
  232.         #\Escape    ~=~ '\033'
  233.         #\Space        ~=~ ' '
  234.         #\BackSlash    ~=~ '\\'
  235.  
  236.     2. Decimal, hexadecimal, octal, and binary notation
  237.  
  238.         Decimal:
  239.         #\dn    where n is a sequence of [0-9]
  240.         #\Dn
  241.         Hexadecimal:
  242.         #\xn    where n is a sequence of [0-9a-fA-F]
  243.         #\Xn
  244.         Octal:
  245.         #\on    where n is a sequence of [0-7]
  246.         #\On
  247.         Binary:
  248.         #\bn    where n is a sequence of [01]
  249.         #\Bn
  250.  
  251. The numeric value of n must be within { 0, ..., 255 }, and the 1-1
  252. mapping from those numeric values to character objects is the same
  253. as the one used for integer->char and char->integer.
  254. ______________________________________________________________________________
  255.  
  256.  
  257. VSCM procedures not present in R4RS -- a brief summary:
  258. ==============================================================
  259.  
  260. ;;
  261. ;; Create a memory image of the running VSCM...
  262. ;;
  263.  
  264. (dump "filename")
  265.  
  266.     - writes a memory image into file "filename" (see above)
  267.  
  268. ;;
  269. ;; Execute a shell command...
  270. ;;
  271.  
  272. (system "shell command")
  273.  
  274.     - return system ("shell command") == 0 ? #t : #f;
  275.  
  276. ;;
  277. ;; Continuations with multiple arguments...
  278. ;;
  279.  
  280. (call-with-values thunk receiver)
  281.  
  282.     - the R5RS (?) ``call-with-values'' primitive
  283.  
  284. (values obj ...)
  285.  
  286.     - the R5RS (?) ``values'' primitive
  287.  
  288. ;;
  289. ;; Handling errors...
  290. ;;
  291.  
  292. (with-error-handler handler thunk)
  293.  
  294.     - equivalent to (thunk) as long as no error occurs
  295.     - calls (handler "error message" ``error-state'') in case of error
  296.     - handler MUST NEVER RETURN
  297.     - ``error-state'' is the continuation of the erroneous computation
  298.     - ``error-state'' CAN NOT BE INVOKED again
  299.     - ``error-state'' is for debugging (error inspection) only
  300.  
  301. ;;
  302. ;; Controlling the garbage collector...
  303. ;;
  304.  
  305. (with-gc-strategy gc-strategy thunk)
  306.  
  307.     - conceptually equivalent to (thunk) with gc-strategy in effect
  308.     - gc-strategy can be:
  309.         * #t - enables verbose GC messages (statistics)
  310.         * a user-supplied GC strategy (i.e. a Scheme procedure)
  311.  
  312. ;;
  313. ;; Handling interrupts...
  314. ;;
  315.  
  316. (with-interrupt-handler handler thunk)
  317.  
  318.     - without interrupts equivalent to (thunk)
  319.     - calls (handler) after SIGINT
  320.     - when (handler) returns the the execution of (thunk) resumes
  321.  
  322. ;;
  323. ;; Raising an error condition...
  324. ;;
  325.  
  326. (error "error message")
  327.  
  328.     - results in error with message "error message"
  329.     - can be caught by with-error-handler
  330.  
  331. ;;
  332. ;; Cpu time measurements...
  333. ;;
  334.  
  335. (clock)
  336.  
  337.     - returns number of milliseconds spent running VSCM so far
  338.  
  339. (gc-clock)
  340.  
  341.     - returns number of milliseconds spent in VSCM's garbage
  342.       collector so far
  343.  
  344. ;;
  345. ;; Accessing the environment...
  346. ;;
  347.  
  348. (getenv "environment variable")
  349.  
  350.     - (getenv "XXX") returns "yyy" if "yyy" is the value of environment
  351.       variable XXX
  352.     - returns #f if XXX is not defined in environment
  353.  
  354. ;;
  355. ;; Shutting down the system gracefully...
  356. ;;
  357.  
  358. (quit)
  359.  
  360.     - exit (EXIT_SUCCESS);
  361.  
  362. (quit integer)
  363.  
  364.     - exit (integer);
  365.  
  366. ;;
  367. ;; The ubiquitous EVAL...
  368. ;;
  369.  
  370. (eval s-expr)
  371.  
  372.     - evaluates s-expr in toplevel environment
  373.  
  374. ;;
  375. ;; Controlling open compilation...
  376. ;;
  377.  
  378. (open-compilation boolean-flag)
  379.  
  380.     - see above
  381.  
  382. ;;
  383. ;; Modified interface to files and file ports...
  384. ;;
  385.  
  386. (remove-file "filename")
  387.  
  388.     - does what it says (OS specific)
  389.  
  390. (rename-file "old-filename" "new-filename")
  391.  
  392.     - does what it says (OS specific)
  393.  
  394. (with-input-from-port port thunk)
  395. (with-output-to-port port thunk)
  396.  
  397.     - do the obvious (analogous to ``with-input-from-file'' and
  398.       ``with-output-to-file'')
  399.  
  400. (open-input-file "filename" [ updt [ binary [ bmode ] ] ])
  401. (open-output-file "filename" [ updt [ binary [ bmode ] ] ])
  402.  
  403.     - if ``updt'' then "+" is added to fopen's mode (open for update)
  404.     - if ``binary'' then "b" is added to fopen's mode (binary file)
  405.     - bmode == #t -> full buffering
  406.            #f -> no buffering
  407.            else  line buffering
  408.     - defaults: updt = #f, binary = #f, bmode = #t
  409.  
  410. (open-append-file "filename" [ updt [ binary [ bmode ] ] ])
  411.  
  412.     - similar to ``open-output-file''
  413.     - subsequent output operations write to the end of the file (fopen
  414.       is called with mode "a")
  415.  
  416. (open-temporary-file)
  417.  
  418.     - returns a file port (as if opened with updt = #t, binary = #t,
  419.       bmode = #t)
  420.     - file is anonymous
  421.     - file is automatically removed when port is closed
  422.  
  423. (close-port port)
  424.  
  425.     - closes any port (``close-input-port'' and ``close-output-port''
  426.       are aliased to this procedure)
  427.  
  428. (flush [output-port])
  429.  
  430.     - writes any data buffered in the port to the external medium
  431.     - if the argument is missing then the current output port will be
  432.       ``flush''ed
  433.  
  434. (seek-and-tell port offset whence)
  435.  
  436.     - works for file ports only
  437.     - works only if the restrictions imposed on the undelying
  438.       ``fseek'' are satisfied
  439.     - sets file position to ``w+offset'', where ``w'' is
  440.         - the beginning of the file if ``whence'' is #t
  441.         - the end of the file if ``whence'' is #f
  442.         - the current position otherwise
  443.     - returns the new position (as a number)
  444.  
  445. (standard-port filedes)
  446.  
  447.     - filedes must be either 0, 1 or 2
  448.     - returns a port object for stdin, stdout or stderr, respectively
  449.  
  450. ;;
  451. ;; Generic ports...
  452. ;;
  453.  
  454. (open-input-generic read read-char peek-char char-ready? close)
  455.  
  456.     - returns a newly created generic input port object
  457.     - all arguments must be parameterless procedures
  458.     - subsequent calls to the primitives ``read'', ``read-char'',
  459.       ``peek-char'', ``char-ready?'', and  ``close-port'' with such a
  460.       port as the (implicit or explicit) argument are transformed
  461.       into calls to the respective procedure associated with the port
  462.  
  463. (open-output-generic write display write-char newline flush close)
  464.  
  465.     - returns a newly created generic output port object
  466.     - all arguments must be procedures
  467.     - ``write'', ``display'', and ``write-char'' must accept one
  468.       argument
  469.     - ``newline'', ``flush'', and ``close'' are parameterless
  470.     - subsequent calls to the primitives ``write'', ``display'',
  471.       ``write-char'', ``newline'', ``flush'', and  ``close-port''
  472.       with such a port as the (implicit or explicit) argument are
  473.       transformed into calls to the respective procedure associated
  474.       with the port
  475.  
  476. ;;
  477. ;; ``Writing'' to and ``reading'' from strings...
  478. ;;
  479.  
  480. (string-write obj)
  481.  
  482.     - returns a newly allocated string containing the sequence of
  483.       characters that would have been sent to the output port by
  484.       ``(write obj)''
  485.  
  486. (string-display obj)
  487.  
  488.     - returns a newly allocated string containing the sequence of
  489.       characters that would have been sent to the output port by
  490.       ``(display obj)''
  491.  
  492. (string-read "string")
  493.  
  494.     - returns TWO values to the caller (similar to ``values'',
  495.       i.e. it requires ``call-with-values'')
  496.     - reads characters from "string" and builds an object just like
  497.       ``read'' does when reading from a file port
  498.     - returns the new object AND a new string which contains the
  499.       remaining characters from the original string
  500.       (white space BEFORE the representation of the object will be
  501.       skipped, but all characters that originally came AFTER the
  502.       object's representation will be returned in the second value)
  503.     - if "string" is empty or contains only white space then
  504.       the first result will be the end-of-file object and the second
  505.       result will be an empty string
  506.  
  507.     Example:
  508.  
  509.       (call-with-values
  510.         (lambda () (string-read "(hello \"world\") @#$% this is Garbage"))
  511.         list)
  512.       =>
  513.       ((hello "world") " @#$% this is Garbage")
  514.  
  515. ;;
  516. ;; Another use of multiple values...
  517. ;;
  518.  
  519. (divide x y)
  520.  
  521.     - returns TWO values to the caller
  522.     - is defined to behave as if it would be declared by:
  523.  
  524.       (define (divide x y)
  525.         (values (quotient x y)
  526.             (remainder x y)))
  527.  
  528.     - performs only one long division internally
  529.  
  530. ;;
  531. ;; Timer...
  532. ;;
  533.  
  534. (timer [ticks])
  535.  
  536.     - always returns the number of ticks left in the timer
  537.     - ``(timer 0)'' turns off the timer
  538.     - ``(timer n)'' with ``n'' being an exact integer > 0 sets the
  539.       number of ticks in the timer to ``n''
  540.  
  541.     - the timer turns off itself upon expiration
  542.     - it is an error for the timer to expire with no ``timer expiration
  543.       handler'' defined in the current context
  544.  
  545. (with-timer-expiration-handler handler thunk)
  546.  
  547.     - both arguments are procedures of 0 arguments
  548.     - ``thunk'' will be called and when the timer expires ``(handler)''
  549.       will run
  550.     - the computation of ``(thunk)'' resumes when ``handler'' returns
  551.  
  552. ;;
  553. ;; Coroutines...
  554. ;;
  555.  
  556. (cr-create proc)
  557.  
  558.     - returns a new coroutine object
  559.     - ``proc'' is a procedure of one argument, defining the body of the
  560.       new coroutine
  561.     - its argument will be supplied by the first ``cr-transfer''
  562.       to the newly created coroutine
  563.  
  564. (cr-transfer coroutine obj)
  565.  
  566.     - transfers control to ``coroutine''
  567.     - ``obj'' is supplied to ``coroutine'' as the return value of
  568.       the most recent ``cr-transfer'' which was executed in the body
  569.       of ``coroutine'' or as the argument to ``proc'' (see ``cr-create'')
  570.     - the active coroutine is implicitly suspended
  571.  
  572. (cr-self)
  573.  
  574.     - returns the coroutine object associated with the active coroutine
  575.  
  576. ;;
  577. ;; Property lists:
  578. ;;
  579.  
  580. (get <symbol> <property>)
  581.  
  582.     - <symbol> and <property> are Scheme symbols
  583.     - returns the property denoted by <property> of <symbol> or #f
  584.       if <property> was not defined for <symbol>
  585.  
  586. (put! <symbol> <property> <obj>)
  587.  
  588.     - <symbol> and <property> are Scheme symbols
  589.     - <obj> can be any Scheme object
  590.     - (re-)defines the property <property> for <symbol> to be <obj>
  591.  
  592. (get-properties <symbol>)
  593.  
  594.     - returns an A-list of <property> - <obj> pairs or #f if no
  595.       properties are defined
  596.  
  597. (set-properies! <symbol> <a-list>)
  598.  
  599.     - replaces the properties of <symbol> by those defined in the
  600.       A-list <a-list>.
  601.  
  602. ;;
  603. ;; Stuff you're not supposed to mess around with... :-)
  604. ;;
  605.  
  606. (execute-asm ...)
  607. (define-asm ...)
  608. (inspect ...)
  609.  
  610.     - compiler/debugger/VM interface
  611.  
  612.  
  613. ______________________________________________________________________________
  614.  
  615. ;;; Appendix:  Implementation of string ports using generic ports
  616.  
  617. (define (open-input-string s)
  618.  
  619.   (let ((l (string-length s))
  620.     (eof (call-with-values (lambda () (string-read "")) (lambda (x y) x))))
  621.  
  622.     (define (read)
  623.       (call-with-values
  624.        (lambda ()
  625.      (string-read s))
  626.        (lambda (obj res)
  627.      (set! s res)
  628.      (set! l (string-length res))
  629.      obj)))
  630.  
  631.   (define (read-char)
  632.     (if (zero? l)
  633.     eof
  634.     (let ((c (string-ref s 0)))
  635.       (set! s (substring s 1 l))
  636.       (set! l (- l 1))
  637.       c)))
  638.  
  639.   (define (peek-char)
  640.     (if (zero? l) eof (string-ref s 0)))
  641.  
  642.   (define (char-ready?) #t)
  643.  
  644.   (define (close) s)
  645.  
  646.   (open-input-generic read read-char peek-char char-ready? close)))
  647.  
  648. (define (open-output-string)
  649.  
  650.   (let ((s ""))
  651.  
  652.     (define (write x)
  653.       (set! s (string-append s (string-write x)))
  654.       x)
  655.  
  656.     (define (display x)
  657.       (set! s (string-append s (string-display x)))
  658.       x)
  659.  
  660.     (define (write-char x)
  661.       (set! s (string-append s (string x)))
  662.       x)
  663.  
  664.     (define (newline)
  665.       (set! s (string-append s "\n"))
  666.       #f)
  667.  
  668.     (define (flush) #f)
  669.  
  670.     (define (close) s)
  671.  
  672.     (open-output-generic write display write-char newline flush close)))
  673.